import { createClass } from "../cfw/tools/class_decorator";
import BaseFileSystem from "./core/fileSystem/BaseFileSystem";
import BaseLogin from "./core/login/BaseLogin";
import BaseRecorder from "./core/recorder/BaseRecorder";
import BaseScreenshot from "./core/screenshot/BaseScreenshot";
import { BaseShare } from "./core/share/BaseShare";
import BaseSubPackage from "./core/subPackage/BaseSubPackage";
import { SDKSystem } from "./core/system/SDKSystem";
import { getChannel, getChannelID, SDKAdParam, SDKDataType } from "./SDKDefine";
import { SDKChannelType, SDKInfo } from "./SDKConfig";
import SDKEvent from "./tools/SDKEvent";
import { BaseChannel } from "./core/channel/BaseChannel";

export class sdk {

    private static channel: BaseChannel;

    static get system(): SDKSystem {
        return this.channel.system;
    }

    static get share(): BaseShare {
        return this.channel.share;
    }

    static get fileSystem(): BaseFileSystem {
        return this.channel.fileSystem;
    }

    static get subPackage(): BaseSubPackage {
        return this.channel.subPackage;
    }

    static get event(): SDKEvent {
        return this.channel.event;
    }

    static get login(): BaseLogin {
        return this.channel.login;
    }

    static get recorder(): BaseRecorder {
        return this.channel.recorder;
    }

    static get screenshot(): BaseScreenshot {
        return this.channel.screenshot;
    }

    static openAd(name: string, param: SDKAdParam) {
        if (param.sytle) {
            this.system.changeStyle(param.sytle)
        }
        this.channel.openAd(name, param)
    }

    static hasConfig(name: string) {
        return this.channel.hasConfig(name)
    }

    static closeAd(name: string, index: number = 0) {
        this.channel.closeAd(name, index)
    }

    static hasAd(name: string): boolean {
        return this.channel.hasAd(name)
    }

    static get channelID(): string {
        return this.channel.id;
    }

    static init(id: string, cfgData: { [key: string]: SDKDataType }, visibleSize: { width: number, height: number }) {
        let channelID: string = getChannelID(id)
        console.log(' sdk init channel id ', id, channelID)
        let data: SDKDataType = cfgData[channelID];
        let config: SDKChannelType = SDKInfo[channelID]
        this.channel = createClass(config.channel);
        let sdk = getChannel()
        this.channel.init(channelID, data, config, sdk)
        this.channel.system.setVisibleSize(visibleSize)
    }
}